package com.lxq.blog.com.lxq.blog.util;

import com.lxq.blog.com.lxq.blog.enums.RoleEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class RoleHandler extends BaseTypeHandler<RoleEnum> {

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, RoleEnum roleEnum, JdbcType jdbcType) {

    }

    @Override
    public RoleEnum getNullableResult(ResultSet resultSet, String s) {
        RoleEnum roleEnum;
        switch (s){
            case "管理员":roleEnum=RoleEnum.ADMIN;break;
            case "会员":roleEnum=RoleEnum.VIP;break;
            case "普通":
            default:roleEnum=RoleEnum.ORDINARY;
        }
        return roleEnum;
    }

    @Override
    public RoleEnum getNullableResult(ResultSet resultSet, int i) {
        return null;
    }

    @Override
    public RoleEnum getNullableResult(CallableStatement callableStatement, int i) {
        return null;
    }
}
